package com.pfizer.pfizerExpertForPad;

import java.util.Date;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

public class DataSyncAlarm {
	static final String ACTION_START_DATASYNC = "com.pfizer.pfizerExpertForPad.ACTION_START_DATASYNC";
	static final String ACTION_START_CHECKDATASYNC = "com.pfizer.pfizerExpertForPad.ACTION_START_CHECKDATASYNC";
	static final String ACTION_START_PFIZERMSG = "com.pfizer.pfizerExpertForPad.ACTION_START_PFIZERMSG";

	public static void setDataSyncAlarm(Context context, boolean IsAlarm,long lNextTime) {
		Intent iDs = new Intent(context, DataSyncReceiver.class);
		iDs.setAction(ACTION_START_DATASYNC);
		PendingIntent piDs = PendingIntent
				.getBroadcast(context, 200938, iDs, 0);
		AlarmManager amDs = (AlarmManager) context
				.getSystemService(Context.ALARM_SERVICE);
		if (IsAlarm) {
			amDs.cancel(piDs);
			amDs.setRepeating(AlarmManager.RTC_WAKEUP, lNextTime,10*60*1000, piDs);
		} else {
			amDs.cancel(piDs);
		}
		iDs = null;
		piDs = null;
		amDs = null;
	}
/*
	public static void setCheckDataSyncAlarm(Context context, boolean IsAlarm) {
		Intent iDs = new Intent(context, CheckDataSyncReceiver.class);
		iDs.setAction(ACTION_START_CHECKDATASYNC);
		PendingIntent piDs = PendingIntent
				.getBroadcast(context, 200968, iDs, 0);
		AlarmManager amDs = (AlarmManager) context
				.getSystemService(Context.ALARM_SERVICE);
		if (IsAlarm) {

			Date dNow = new Date();
			amDs.setRepeating(AlarmManager.RTC_WAKEUP, dNow.getTime() + 20*1000,
					12 * 60 * 1000, piDs);
		} else {
			amDs.cancel(piDs);
		}
		iDs = null;
		piDs = null;
		amDs = null;
	}
*/
	public static void setPfizerMsgAlarm(Context context,int intrevalTime, boolean IsAlarm) {
		Intent iDs = new Intent(context, PfizerMsgReceiver.class);
		iDs.setAction(ACTION_START_PFIZERMSG);
		PendingIntent piDs = PendingIntent
				.getBroadcast(context, 200998, iDs, 0);
		AlarmManager amDs = (AlarmManager) context
				.getSystemService(Context.ALARM_SERVICE);
		if (IsAlarm) {
			amDs.cancel(piDs);
			Date dNow = new Date();
			amDs.setRepeating(AlarmManager.RTC_WAKEUP, dNow.getTime() + 1000,
					intrevalTime * 60 * 1000, piDs);
		} else {
			amDs.cancel(piDs);
		}
		iDs = null;
		piDs = null;
		amDs = null;
	}
}
